package com.qiqu.controller;

import com.qiqu.service.UsersCollectionService;
import com.qiqu.utils.JSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import static com.qiqu.commen.Const.PAGE_SIZE;


/**
 * (UsersLikeArticle)表控制层
 *
 * @author makejava
 * @since 2021-04-12 20:47:36
 */
@RestController
@RequestMapping("usersCollection")
@Api(value = "收藏相关接口",tags = {"收藏相关接口controller"})
public class UsersCollectionController {
    @Resource
    private UsersCollectionService usersCollectionService;


    //用户收藏
    @ApiOperation(value = "收藏喜欢文章--fk", notes = "收藏喜欢文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "articleId", value = "收藏的文章id", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "userId", value = "收藏者的id", required = true, dataType = "string", paramType = "query")
    })
    @GetMapping("/collection")
    public JSONResult collection(String userId,String articleId){

        return  JSONResult.ok(usersCollectionService.collection(userId,articleId));
    }

    //用户取消收藏
    @ApiOperation(value = "收藏取消喜欢--fk", notes = "收藏取消喜欢")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "取消收藏的人的id", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "articleId", value = "取消收藏的文章id", required = true, dataType = "string", paramType = "query")
    })
    @GetMapping("/unCollection")
    public JSONResult unCollection(String userId,String articleId){

        return JSONResult.ok(usersCollectionService.cancleCollection(userId,articleId));
    }
    //查询用户是否收藏文章
    @ApiOperation(value = "查询用户是否收藏文章--kk", notes = "查询用户是否收藏文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "articleId", value = "文章id", required = true, dataType = "string", paramType = "query")
    })
    @GetMapping("/isCollection")
    public JSONResult isCollection(HttpServletRequest request, String articleId){
        String userId=request.getHeader("userId");
        return JSONResult.ok(usersCollectionService.isCollection(userId,articleId));
    }

    //获取用户收藏信息
    @ApiOperation(value = "获取用户收藏信息--fk",notes = "获取用户收藏信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name="page",value = "页码",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name="userId",value = "用户id",required = true,dataType = "string",paramType = "query"),
    })
    @GetMapping("/getCollection")
    public JSONResult getCollection(Integer page,String userId) {
        if(page == null){
            page=1;
        }
        return JSONResult.ok(usersCollectionService.getCollection(page,PAGE_SIZE,userId));
    }


    //获取未读收藏信息数
    @ApiOperation(value = "获取未读收藏信息数--fk",notes = "获取未读收藏信息数")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name="userId",value = "用户id",required = true,dataType = "string",paramType = "query")
    })
    @GetMapping("/getCollectionCounts")
    public JSONResult getCollectionCounts(String userId) {
        return JSONResult.ok(usersCollectionService.queryStatusCount(userId));
    }

    //更新状态信息
    @ApiOperation(value = "更新状态信息--fk",notes = "更新状态信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name="userId",value = "用户id",required = true,dataType = "string",paramType = "query")
    })
    @GetMapping("/updateCollection")
    public JSONResult updateCollection(String userId) {
        return JSONResult.ok(usersCollectionService.updateStatus(userId));
    }

}